// 格式化日期字符串
function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  if (month < 10) {
    month = "0" + month;
  }
  var day = date.getDate()
  if (day < 10) {
    day = "0" + day;
  }

  var hour = date.getHours()
  if (hour < 10) {
    hour = "0" + hour;
  }
  var minute = date.getMinutes()
  if (minute < 10) {
    minute = "0" + minute;
  }
  var second = date.getSeconds()
  if (second < 10) {
    second = "0" + second;
  }

  return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}

module.exports = {
  formatTime: formatTime,
  logToServer: logToServer,
  getGPSDomain: getGPSDomain,
  setStorage: setStorage,
  getStorage: getStorage
}

function logToServer(user, logData) {
  // var url = 'https://gps.dituhui.com/wxweb/weixin'
  // wx.request({
  //   url: url,
  //   data: {
  //     a: user,
  //     log: logData
  //   },
  //   header: {
  //     'content-type': 'application/json'
  //   },
  //   success: function (res) {
  //     console.log('logToServer成功')
  //   },
  //   fail: function (e) {
  //     console.log('logToServer失败')
  //     // console.log('logToServer失败' + e.detail.errMsg)
  //   }
  // })
}

function getGPSDomain() {
  return 'https://gps.dituhui.com'
}

// 同步
function getStorage(key) {
  var value = wx.getStorageSync(key)
  return value
}

// 异步
function setStorage(key, value) {
  wx.setStorage({
    key: key,
    data: value
  })
}